//
//  CommentCell.m
//  GIFShow
//
//  Created by lanou11air029 on 15/4/15.
//  Copyright (c) 2015年 CK. All rights reserved.
//

#import "CommentCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
@interface CommentCell()
@property (strong, nonatomic) UIImageView * userHeaderIcon;
@property (strong, nonatomic) UILabel * userNameLabel;
@property (strong, nonatomic) UILabel * likeLabel;
@property (strong, nonatomic) UILabel * commentLabel;
@end
@implementation CommentCell

- (void)awakeFromNib {
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.clipsToBounds = YES;
        [self setupSubViews];
    }
    return self;
}
-(void)setupSubViews{
    self.userHeaderIcon = [[UIImageView alloc]init];
    self.userNameLabel = [[UILabel alloc]init];
    self.likeLabel = [[UILabel alloc]init];
    self.commentLabel = [[UILabel alloc]init];

    self.userHeaderIcon.frame = CGRectMake(20, 10, self.bounds.size.width * 0.1, self.bounds.size.width * 0.1);
    self.userHeaderIcon.layer.cornerRadius = self.bounds.size.width * 0.05;
    self.userHeaderIcon.layer.masksToBounds = YES;
    self.userNameLabel.frame = CGRectMake(self.userHeaderIcon.frame.size.width + 23, 10, self.bounds.size.width * 0.6,30);
    CGRect frame = [UIScreen mainScreen].bounds;
    self.likeLabel.frame = CGRectMake(frame.size.width - 50, 10, 123, self.bounds.size.width * 0.1);
    self.commentLabel.frame = CGRectMake(20, self.userHeaderIcon.frame.origin.y+self.userHeaderIcon.frame.size.height+2, self.bounds.size.width-40, 50);

    self.commentLabel.numberOfLines = 0;

    [self.contentView addSubview:self.userHeaderIcon];
    [self.contentView addSubview:self.userNameLabel];
    [self.contentView addSubview:self.likeLabel];
    [self.contentView addSubview:self.commentLabel];
}
-(void)setCommentModel:(MYCommentModel *)commentModel{
    if(_commentModel != commentModel){
        _commentModel = commentModel;
        [self configCell];
    }
}
-(void)configCell{
    NSString * imageStr = [self.commentModel.userinfo valueForKey:@"avatar"];
    [self.userHeaderIcon sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    self.userNameLabel.text = [self.commentModel.userinfo valueForKey:@"nickname"];
    self.userNameLabel.textColor = [UIColor lightGrayColor];
    NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"顶:%@",self.commentModel.ding] attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.5 green:1 blue:1 alpha:0.9]}];
    [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:1 green:0.5 blue:0.2 alpha:0.9] range:NSMakeRange(0, 1)];
    self.likeLabel.attributedText = attStr;
    self.commentLabel.text = self.commentModel.content;
    self.commentLabel.font = [UIFont systemFontOfSize:14];
    [self.commentLabel sizeToFit];

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
